package com.cxg.fairy.example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.widget.Toast;

import com.cxg.fairy.activities.ProxyActivity;
import com.cxg.fairy.app.AccountManager;
import com.cxg.fairy.app.IUserChecker;
import com.cxg.fairy.app.Latte;
import com.cxg.fairy.delegates.LatteDelegate;
import com.cxg.fairy.ec.main.EcBottomDelegate;
import com.cxg.fairy.ec.sign.ISignListener;
import com.cxg.fairy.ec.sign.SignInDelegate;
import com.cxg.fairy.ui.launcher.ILauncherListener;
import com.cxg.fairy.ui.launcher.OnLauncherFinishTag;

import cn.jpush.android.api.JPushInterface;
import qiu.niorgai.StatusBarCompat;

public class ExampleActivity extends ProxyActivity implements
        ISignListener,
        ILauncherListener {

    private LatteDelegate delegate = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        Latte.getConfigurator().withActivity(this);
        StatusBarCompat.translucentStatusBar(this, true);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    public LatteDelegate setRootDelegate() {
//        return new SignUpDelegate();
//        return SignUpByNoDelegate.create("13905105588", "5555");
//        return new SignInDelegate();
//        return new LauncherDelegate();
        AccountManager.checkAccount(new IUserChecker() {
            @Override
            public void onSignIn() {
                delegate =  new EcBottomDelegate();
            }

            @Override
            public void onNotSignIn() {
                delegate = new SignInDelegate();
            }
        });
        return delegate;
    }

    @Override
    public void onSignInSuccess() {
        Toast.makeText(this, "登录成功", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onSignUpSuccess() {
        Toast.makeText(this, "注册成功", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onLauncherFinish(OnLauncherFinishTag tag) {
        switch (tag) {
            case SIGNED:
                Toast.makeText(this, "启动结束，用户登录了", Toast.LENGTH_LONG).show();
                getSupportDelegate().startWithPop(new EcBottomDelegate(0));
                break;
            case NOT_SIGNED:
                Toast.makeText(this, "启动结束，用户没登录", Toast.LENGTH_LONG).show();
                getSupportDelegate().startWithPop(new SignInDelegate());
                break;
            default:
                break;
        }
    }

}
